package com.example.takeoff.controller;


import com.example.takeoff.common.Result;
import com.example.takeoff.service.impl.CheckServiceImpl;
import com.example.takeoff.utils.SendNoteUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@RestController
@RequestMapping(value = "/api/note")
public class SendNoteController
{
    @Autowired
    private SendNoteUtil sendNoteUtil;
    @Autowired
    private CheckServiceImpl checkService;

    @RequestMapping(value = "/sendNote", method = RequestMethod.GET)
    public void sendNote(String phone, HttpServletResponse response)
    {
        String template = "SMS_267000131";
        try
        {
            String code = sendNoteUtil.sendNoteMessage(phone, template);
            checkService.createCode(phone, code);
            response.getWriter().write(sendNoteUtil.sendNoteMessage(phone, template));
        }
        catch (IOException e)
        {
            e.printStackTrace();
        }
    }
}

